package com.starlink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starlink.model.domain.AdminRoleDO;
import com.starlink.model.domain.RoleDO;
import com.starlink.model.request.AdminRoleRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface AdminRoleMapper extends BaseMapper<AdminRoleDO> {
    AdminRoleDO selectDOByAdminId(Long adminId);
    List<AdminRoleDO> selectDOList(AdminRoleDO adminRole);
    int insertDO(AdminRoleDO adminRole);
    int batchInsertDO(List<AdminRoleDO> adminRoleDOList);
    int updateDO(AdminRoleDO adminRole);
    int deleteDOByAdminId(Long adminId);
    int deleteDOByAdminIds(String[] adminIds);

    @Select({"<script>",
            "   select count(1) from admin_role",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") AdminRoleRequest param);
    @Select({"<script>",
            "   select * from admin_role",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<AdminRoleDO> pageQuery(@Param("param") AdminRoleRequest param, @Param("limit") int limit, @Param("offset") long offset);

    @Select("select role.* from admin_role right JOIN role on admin_role.role_id = role.id where admin_role.admin_id = #{adminId} ")
    List<RoleDO> findByAdminId(@Param("adminId") long adminId);
}
